<template>
    <div class="goods-list">
        <div v-for="item in goodslist" @click="leapDetail(item.id)" :key="item.id">
            <img :src="item.img1" >
            <p class="title">{{item.title}}</p>
            <p class="price">￥{{item.price}}</p>
            <p class="submit">{{item.deal}}</p>
        </div>
    </div>
    <button class="lookfor">查看更多</button>
</template>

<script lang="ts" setup>
import {getGoodsList} from "@/api/home"
import {ref} from 'vue'
import { useRouter } from "vue-router";
const $router = useRouter()
const goodslist:any = ref("")
getGoodsList().then((res:any)=>{
   if(res.code == '200'){
     goodslist.value = res.data
   }
    
})
function leapDetail(n:any){
  $router.push({path:"/goodsDetail",query:{goodsid:n}})
  
  console.log('n: ', n);
}
</script>

<style scoped>
.goods-list{
    width: 100%;
  font-size: 14px;
  column-count: 2;
  column-gap:5px;
}
.goods-list div{
    width: 100%;
  text-align: center;
  break-inside: avoid;
  background-color: white;
  margin-bottom: 5px;
  border-radius: 10px;
  box-sizing: border-box;
  padding: 5px;
}
.goods-list img{
    width: 95%;
}
.title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  font-size: 14px;
}
.price {
  text-align: left;
  font-size:16px;
  line-height: 6px;
  color: #1a9956;
  margin-top: 4px;
  font-weight: bold; 
  margin-top: 15px;
}
.submit{
    text-align: left;
    font-size: 12px;
    color: #a9a9a9;
    margin-top: 15px;
}
.lookfor{
  width: 80px;
  height: 40px;
  background: #1a9956;
  color: white;
  font-size: 16px;
  text-align: center;
  margin-bottom: 80px;
  border: none;
  border-radius: 6px;
  position: relative;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
}
</style>